import time

from appium.webdriver.common.appiumby import AppiumBy


from page.base_page import BasePage
from page.member_detail_page import MemberDetailPage


class SearchPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)

    def search_name(self, keyword):
        self.find(AppiumBy.CSS_SELECTOR, 'android.widget.EditText').clear().send_keys(keyword)
        time.sleep(3)
        name_lists = self.finds(AppiumBy.XPATH,
                                '/android.widget.ListView//android.view.ViewGroup/android.widget.TextView/')
        return [name_list.text for name_list in name_lists]

    def to_search_detail(self, n=0) -> MemberDetailPage:
        result_list = self.finds(AppiumBy.XPATH,
                                 '//android.widget.ListView//android.view.ViewGroup')
        result_list[n].click()
        return MemberDetailPage(self.driver)

